package com.bishe.demo.modules.common.dao;

import com.bishe.demo.modules.common.entity.City;
import com.bishe.demo.modules.common.entity.TimeTable;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @Description TimeTableDao
 * @Author Lubb
 * @Date 2021/3/30 10:37
 */
@Repository
@Mapper
public interface TimeTableDao {
    @Insert("insert into common_timetable(arrival_time,departure_time,residence_time) values(" +
            "#{arrivalTime},#{departureTime},#{residenceTime})")
    void addTimeTable(TimeTable timeTable);

    @Delete("delete from common_timetable where id = #{id}")
    void deleteTimeTableById(Integer id);

    @Update("update common_timetable set arrival_time=#{arrivalTime}, departure_time=#{departureTime}, " +
            "residence_time=#{residenceTime}")
    void updateTimeTable(TimeTable timeTable);

    @Select("select * from common_timetable where id = #{id}")
    TimeTable getTimeTableById(Integer id);

    @Select("SELECT\n" +
            "\t*\n" +
            "FROM\n" +
            "\tcommon_timetable AS ct\n" +
            "LEFT JOIN ticket_site_table AS tst ON tst.fk_time_id = ct.id\n" +
            "WHERE\n" +
            "\ttst.fk_time_id = #{fkTimeId} ")
    TimeTable getTimeTableByFkTimeId(Integer fkTimeId);
}
